package com.yshkj.payment.service.impl;

import com.yshkj.payment.entity.Demo;
import com.yshkj.payment.repository.DemoRepository;
import com.yshkj.payment.repository.builder.DemoSpecificationBuilder;
import com.yshkj.payment.service.DemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * Created by 唐旭 on 2016/8/25.
 */
@Service
@Transactional
public class DemoServiceImpl implements DemoService {
    @Autowired
    private DemoRepository demoRepository;
    @Autowired
    private DemoSpecificationBuilder builder;

    public Demo addDemo() {
        Demo s = new Demo()
                .setName("test")
                .setUuid("123");
        demoRepository.save(s);
        return s;
    }

    @Transactional(readOnly = true)
    public List<Demo> list(Map<String, Object> query) {
        Page<Demo> all = demoRepository.findAll(builder.list(query), new PageRequest(0, 10));
        return all.getContent();
    }
}
